package in

type ResponseCount struct {
	Code  interface{} `json:"code"`
	Data  interface{} `json:"data"`
	Msg   interface{} `json:"msg"`
	Count int64       `json:"count"`
}

type Response struct {
	Code interface{} `json:"code"`
	Data interface{} `json:"data"`
	Msg  interface{} `json:"msg"`
}

func newResponse(code bool, v interface{}) Response {
	l := Response{Code: codeFail, Msg: ""}
	switch val := v.(type) {
	case error:
		if val != nil {
			l.Data = val.Error()
			l.Msg = val.Error()
		}
	default:
		l.Data = v
		if !code {
			l.Msg = v
		}
	}
	if code {
		l.Code = codeSuccess
	}
	return l
}

func (this Response) toCount(co int64) ResponseCount {
	return ResponseCount{
		Code:  this.Code,
		Data:  this.Data,
		Msg:   this.Msg,
		Count: co,
	}
}
